//
//  AppController.h
//  ABlip
//
//  Created by dawid on 08-12-21.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "PreferenceController.h"
#import <Growl/Growl.h>
#import "BlipMessage.h"

#import "MessageTextField.h"
#import "ABlipConstants.h"

#import "ClickableNSImageView.h"
#import "VBoxView.h"
#import "MessageTextField.h"

#define KeyChainItemName @"haslo do konta"
#define KeyChainItemKind @"ABlip"
#define GrowlDefaultNotification @"ABlip Growl Notification"
#define ErrorDescription @"ErrorDescriptionKey"
#define ABL_USER_INFO_QUOTE @"quoteText"
#define ABL_USER_INFO_DELETE @"deletePath"
#define ABL_DIRECTED_MESSAGE @"DirectedMessage"
#define ABL_PRIVATE_MESSAGE @"PrivateMessage"
#define ABL_STATUS_MESSAGE @"Status"
#define ABL_REGEX_DELETE_TYPES @"^DirectedMessage|PrivateMessage|Status$"
#define ABL_REGEX_TO_ME_TYPES @"^DirectedMessage|PrivateMessage|Notice$"
#define BOUNDARY @"----------------------------897a0b433c89"
#define IMAGE_EXTENSIONS @"^[jJ][pP][eE][gG]|[jJ][pP][gG]|[bB][mM][pP]|[gG][iI][fF]|[pP][nN][gG]|[tT][iI][fF][fF]$"
#define IMAGE_PASTED_NAME @"obrazek.tiff"
#define PICTURE_DIR_NAME @"Pictures"

@class MyPreviewItem;

typedef void * CGSConnectionID;

@interface AppController : NSObject <GrowlApplicationBridgeDelegate>{
	IBOutlet NSTextView *textBox;
	IBOutlet NSTextField *loginField;
	IBOutlet NSTextField *passwordField;
	IBOutlet NSScrollView *scrollView;
	IBOutlet NSPanel *hudWindow;
	IBOutlet NSPanel *loginWindow;
	IBOutlet NSImageView *pictureView;
	IBOutlet NSButton *homeButton;
	IBOutlet NSButton *allBlipsButton;
	IBOutlet NSButton *directedBlipsButton;
	NSProgressIndicator *refreshIndicator;
	IBOutlet NSButton *refreshButton;
	IBOutlet NSScrollView* scrollViewPriv;
	NSImageView *messangerView;
	NSLock *operationLock;
	NSMutableArray* blipMessages;
	NSMutableArray* userNames;
	NSMutableArray* msgViews;
	NSMutableArray* msgToMeViews;
	NSMutableArray *privateMsgIndexes;
	NSString *userLogin;
	NSString *userPassword;
	NSString *lastUpdateId;
	NSString *avatarSavePath;
	NSTimer *timer;
	NSImageView *bottom;
	
	ClickableNSImageView *gradient;
	float opacity;
	int maxMessagesShow;
	int refreshInterval;
	BOOL growlReady;
	PreferenceController* preferenceController;
	int messagesTypeVisible;
	BOOL hideAfterSendMsg;
	BOOL shortKeyCall;
	BOOL isFirstRun;
	BOOL activeQuickLook;
	BOOL hideGrowlNotif;
	BOOL hideIconBadge;
	BOOL showYoutube;
	int asyncConnectionCounter;
	NSOperationQueue *queue;
	int newMessagesCount;
	int lastTypeMsgShow;
	BOOL textBoxBocked;
	NSRect quickLookRect;
	NSMatrix *matrixView;
	VBoxView* updView;
	VBoxView* privView;
	NSFontPanel* theFontPanel;
	//NSImage *background;
  
  MyPreviewItem* previewURL;
  
  BOOL realQuickLook;
}
+ (id)shared;
@property (readwrite)NSButton* allBlipsButton;
@property (readwrite)float opacity;
@property (readwrite) int maxMessagesShow;
@property (readwrite) int refreshInterval;
@property (readwrite, copy) NSString *lastUpdateId;
@property (readwrite) int messagesTypeVisible;
@property (readwrite, copy) NSString *userPassword;
@property (readwrite) BOOL hideAfterSendMsg;
@property (readwrite) BOOL isFirstRun;
@property (readwrite) BOOL textBoxBocked;
@property (readwrite) BOOL hideGrowlNotif;
@property (readwrite) BOOL hideIconBadge;
@property (readwrite) BOOL showYoutube;
@property (readwrite) BOOL shortKeyCall;
@property (readwrite, copy) NSMutableArray* userNames;
@property (readwrite, copy) NSMutableArray* blipMessages;
@property (readwrite) NSTextView* textBox;


-(IBAction)getAvatar:(id)sender;
- (IBAction)ShowFontPanel:(id)sender;
-(IBAction)showPreferencePanel:(id)sender;
-(IBAction)hideShowGrowl:(id)sender;
-(void)setUserLogin:(NSString*)userName;
-(NSString*)userLogin;
-(void)setUserPassword:(NSString*)passwd;
-(NSString*)userPassword;
-(void)checkLoginStatus;

-(IBAction)trySaveToKeyChain:(id)sender;
- (void)modifyItemFromKeychain:(NSString*)login password:(NSString*)passwd;
- (NSString*)getPasswordFromKeychainForLogin:(NSString*)login;
- (void)displayAlertWithMessageText:(NSString *)messageText;

- (void)initializeGrowl; 
-(void)sendGrowlMessage:(BlipMessage*)message;
-(void)sendGrowlDownloadingMsg;
-(void)initializeTimer;
-(void)stopTimer;
-(void)showWindow;
-(void)setViewsInScrollView;
-(void)hideApp;
+(NSString*)appSupportDir;
+(NSString*)picturesDownloadDir;
-(void)deleteFileAtPath:(NSString*)path;
-(void)deleteBlipMessages:(NSRange)atRange;
- (void)quickLookSelectedItems:(NSString*)imagePath;
- (BOOL)userDidPressSpaceInOutlineView:(NSString*)imagePath;

-(NSString*)checkDownloadData:(NSData*)data;
-(void)hideRefreshButton;
-(void)unHideRefreshButtton;
-(IBAction)manualRefresh:(id)sender;
-(IBAction)openDashboard:(id)sender;
-(IBAction)allBlipsClick:(id)sender;
-(IBAction)directedBlipClick:(id)sender;
-(IBAction)changeMessageToType:(id)sender;
-(IBAction)hideShowApp:(id)sender;
-(BOOL)changeVisibleMessagesTo:(int)visibleMsgType;
-(void)sendGrowlMoreMessages:(NSString*)moreMsgCount;
-(void)resetTextBox;
-(void)blockTextBox;
-(void)sendRequestWithSubscription;
-(void)msgRecipientNotExist;
-(void)addAttachmentToBox;
-(void)openUserDashboard:(NSString*)userToDisplay;
-(void)showMessanger:(NSString*)textToShow;
-(void)hideMessanger;
- (void)enableBlurForWindow:(NSWindow *)window;
-(void)createBlipMsg;

- (IBAction)decreaseFontSizeAction:(id)sender;
- (IBAction)increaseFontSizeAction:(id)sender;

- (NSRect) previewPanel: (id) panel sourceFrameOnScreenForPreviewItem: (id /*<QLPreviewItem>*/) item;
@end
